# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=coreutils
pkgbase=mingw-w64-uutils-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-uutils-${_realname}")
pkgver=0.1.0
pkgrel=1
pkgdesc="Cross-platform Rust rewrite of the GNU coreutils (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/uutils/coreutils'
msys2_references=(
  'archlinux: uutils-coreutils'
  'purl: pkg:cargo/coreutils'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-oniguruma" "${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("https://github.com/uutils/coreutils/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('55c528f2b53c1b30cb704550131a806e84721c87b3707b588a961a6c97f110d8')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  export RUSTONIG_DYNAMIC_LIBONIG=1
  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  make PROFILE=release
}

package() {
  cd "${_realname}-${pkgver}"

  make install \
    DESTDIR="${pkgdir}" \
    PREFIX="${MINGW_PREFIX}" \
    PROG_PREFIX=uu- \
    PROFILE=release

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/uutils-${_realname}/LICENSE"
}
